package fast.calc.warlock;

import fast.calc.Buffs;
import fast.calc.Fast;
import fast.calc.Stats;
import fast.calc.WeaponStats;
import fast.data.BaseStats;
import fast.data.Spec;
import fast.data.Stat;

import java.util.Map;

public class FastWarlock extends Fast {

	//private static final double reaction_time = 0.5;
	
	public FastWarlock(BaseStats bs){
		stats = new Stats();
		stats.setBuffs(new Buffs()); // raid buffs
		stats.getBuffs().setBuffs(Buffs.validBuffs);
		stats.setSpec(bs.getSpec());
		stats.add(bs);
		
		stats.setMh(new WeaponStats(bs.getMH().dps, bs.getMH().speed, bs.getMH().type));
		if(bs.getOH() != null)
			stats.setOh(new WeaponStats(bs.getOH().dps, bs.getOH().speed, bs.getOH().type));
		
		stats.setGearBuffs(bs.getGearBuffs());
		stats.setGearBuffItemLevel(bs.getGearBuffItemLevel());
		if(!bs.getMH().getEnchant().equals(""))
			stats.getGearBuffs().getGearBuffs().add("mh_"+bs.getMH().getEnchant());
		if(!bs.getOH().getEnchant().equals(""))
			stats.getGearBuffs().getGearBuffs().add("oh_"+bs.getOH().getEnchant());
		
		for(String gbs : stats.getGearBuffs().getGearBuffs()){
			System.out.println("gb " + gbs);
		}

		stats.setSetItems(bs.getSetItems());
		stats.setTalents(bs.getTalents());
		stats.setGlyphs(bs.getGlyphs());
		
//		for(String sbs : stats.getGearBuffs().getSetItems()){
//			System.out.println("setitems " + sbs);
//		}
//		for(String t : bs.getTalents()){
//			System.out.println("talents " + t);
//		}
//		for(String gl : bs.getGlyphs()){
//			System.out.println("||glyph " + gl);
//		}
		calc();
	}
	
	public FastWarlock(){
		stats = new Stats();
	}
	
	public Map<String, Double> getEP() {
		return ep;
	}
	
	private void calc(){
		dps1 = get_dps();
		System.out.println("DPS: " + dps1);
	}
	
	protected double get_dps(){
		if(stats.getSpec() == Spec.Affliction)
			calc_dps_affliction();
		else if(stats.getSpec() == Spec.Demonology)
			calc_dps_demonology();
		else if(stats.getSpec() == Spec.Destruction)
			calc_dps_destruction();
		
		return Math.max(dps1, 1.0);
	}
	
	private void calc_dps_affliction() {
		ep.put("int", 4.94);
		ep.put("sp", 4.00);
		ep.put("white_hit", 2.53);
		ep.put("crit", 1.97);
		ep.put("haste", 2.40);
		ep.put("mastery", 2.77);
		ep.put("exp", 0.0);
		ep.put("spi", 0.0);
		
		dps1 = sum_ep();
	}
	
	private void calc_dps_demonology() {
		ep.put("int", 4.37);
		ep.put("sp", 3.53);
		ep.put("white_hit", 3.33);
		ep.put("crit", 1.94);
		ep.put("haste", 1.60);
		ep.put("mastery", 1.93);
		ep.put("exp", 0.0);
		ep.put("spi", 0.0);
		
		dps1 = sum_ep();
	}
	
	private void calc_dps_destruction() {
		ep.put("int", 4.36);
		ep.put("sp", 3.48);
		ep.put("white_hit", 3.10);
		ep.put("crit", 1.99);
		ep.put("haste", 1.73);
		ep.put("mastery", 2.19);
		ep.put("exp", 0.0);
		ep.put("spi", 0.0);
		
		dps1 = sum_ep();
	}
	
	public double sum_ep(){
		double dps = 0.0;
		for(Stat stat : Stat.possibleStats){
			if(stat == Stat.hit){
				int cap = 5100;
				if(stats.getStat(stat) > cap)
					dps += cap * ep.get(stat.getEpName());
				else
					dps += stats.getStat(stat) * ep.get(stat.getEpName());
			}else if(ep.get(stat.getEpName()) != null){
				dps += stats.getStat(stat) * ep.get(stat.getEpName());
			}
		}
		return dps;
	}
	

	@Override
	protected double get_total_speed() {
		return 0;
	}
}
